<template>
  <div>
    <!-- 顶部导航区域 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item' ,item.id == 0?'mui-active':'']"
            v-for="(item) in create"
            :key="item.id"
            @click="getPhotoById(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>

    <!-- 图片区域 -->
    <ul class="photolist">
      <router-link v-for="item in list" :key="item.id" :to="'/home/PhotoInfo/'+item.id" tag="li">
        <img v-lazy="item.img_url">
        <div class="info">
          <p class="title">{{item.title}}</p>
          <p class="body">{{item.zhaiyao}}</p>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.js";

export default {
  data() {
    return {
      create: [],
      list: []
    };
  },
  created() {
    this.getAllCreate();
    this.getPhotoById(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
   async getAllCreate() {
     await this.$http.get("api/getimgcategory").then(result => {
        if (result.data.status === 0) {
          result.data.message.unshift({ title: "全部", id: 0 });
          this.create = result.data.message;
        }
      });
    },
   async getPhotoById(id) {
     await this.$http.get("api/getimages/" + id).then(result => {
        if (result.data.status == 0) {
          this.list = result.data.message;
        }
      });
    }
  }
};
</script>
<style scoped>
li {
  list-style: none;
}
.mui-slider {
  touch-action: pan-x;
}
.photolist {
  margin: 0;
  padding: 10px;
  text-align: center;
}
.photolist li {
  margin: 10px 0;
  position: relative;
}
.photolist li img {
  width: 100%;
  border-radius: 5px;
  box-shadow: 0 0px 4px gainsboro;
  vertical-align: middle;
}
img[lazy="loading"] {
  width: 40px;
  height: 300px;
  margin: auto;
}
.info {
  text-align: left;
  color: white;
  background-color: rgba(0, 0, 0, 0.5);
  position: absolute;
  bottom: 0;
  /* max-height: 85px; */
}
.title {
  color: white;
  font-weight: bold;
  padding: 5px;
}
.body {
  color: white;
  padding: 5px;
  padding-top: 0;
  font-size: 12px;
  padding-bottom: 0;
}
</style>


